#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
const int K=1e6+5;
int T,n,a[N],t[K],maxx=-1;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        int ans=0;
        memset(t,0,sizeof(t));
        for(int i=1; i<=n; i++){
            cin>>a[i];
            t[a[i]]++;
            maxx=max(maxx,a[i]);

        }
        for(int i=1; i<=maxx; i++){
            if(t[i]>=2) ans+=i*(t[i]-1);
        }
        cout<<ans<<endl;
    }
    return 0;
}
